function* foo() {
  console.log(`start`)
  try {
    const res = yield 'foo';// next方法返回值
    console.log('res:', res)
  } catch (error) {
    console.log('error:', error)
  }
}

const generator = foo();

const result = generator.next()
console.log('result:', result)

generator.next('bar')

generator.throw(new Error('error'))// 抛出异常